OBJ = ../obj
LIB = ../lib

ifdef DEBUG
  OPTIMIZE = -O2 -g
else
  OPTIMIZE = -O2
  CLDFLAGS = -Wl,--strip-all
endif

DEFINES = -DHAVE_GUI
INCLUDES := $(shell pkg-config --cflags gtk+-2.0)
LIBS := $(shell pkg-config --libs gtk+-2.0)
CFLAGS = $(OPTIMIZE) $(INCLUDES) $(DEFINES) -Wall -fPIC

CXX = g++

all: dummy ${LIB}/geoffs_modules.so.0

dummy:
	mkdir ${OBJ} 2> /dev/null || true
	mkdir ${LIB} 2> /dev/null || true

${LIB}/geoffs_modules.so.0: ${OBJ}/analog_source.o ${OBJ}/momentary_encoder.o \
                            ${OBJ}/potentiometer.o ${OBJ}/module_manager.o
	${CXX} -shared -o $@ $^ ${LIBS}
	rm -f ${LIB}/geoffs_modules.so
	ln -s $@ ${LIB}/geoffs_modules.so

${OBJ}/analog_source.o: analog_source.cc analog_source.h
	echo ${INCLUDES}
	echo ${LIBS}
	$(CXX) $(CFLAGS) -c $< -o $@

${OBJ}/momentary_encoder.o: momentary_encoder.cc momentary_encoder.h
	$(CXX) $(CFLAGS) -c $< -o $@

${OBJ}/potentiometer.o: potentiometer.cc potentiometer.h
	$(CXX) $(CFLAGS) -c $< -o $@

${OBJ}/module_manager.o: module_manager.cc potentiometer.h momentary_encoder.h analog_source.h
	$(CXX) $(CFLAGS) -c $< -o $@

clean :
	rm -f ${OBJ}/*.o ${LIB}/*.so*
